package com.veo;

import com.veo.bean.Car;
import com.veo.bean.Taxi;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

@SpringBootApplication
//默认扫描主程序类所在包下面的所有包和类
public class Springboot01Application {

    public static void main(String[] args) {
        //返回IOC容器
        ConfigurableApplicationContext context = SpringApplication.run(Springboot01Application.class, args);
//
//        User user1 = (User) context.getBean("user01");
//        User user2 = (User) context.getBean("user01");
//        System.out.println(user1);
//        System.out.println(user1 == user2);
//
//        System.out.println("=================");
//
//        MyConfig config = context.getBean(MyConfig.class);
//        System.out.println(config);
//
//        System.out.println("=================");
//        //proxyBeanMethods=false,bean依赖的bean调用的方法时springboot底层不检查ioc容器，直接调用方法，返回一个new的对象，速度快
//        Pet tom = context.getBean("tom",Pet.class);
//        System.out.println("用户的宠物：" + (user1.getPet() == tom));
//
//        System.out.println("=================");
//
//        String[] names = context.getBeanNamesForType(User.class);
//        Arrays.stream(names).forEach(System.out::println);
//        String[] names1 = context.getBeanNamesForType(DBHelper.class);
//        Arrays.stream(names1).forEach(System.out::println);

//        System.out.println(context.containsBean("tom"));
//        System.out.println(context.containsBean("user01"));
//
//        System.out.println("+++++++++++++");
//        System.out.println(context.getBean("taxi1", Taxi.class));
//
//        String[] names = context.getBeanNamesForType(Car.class);
//        for (String name : names) {
//            System.out.println(name);
//        }
//
//        System.out.println(context.getBean(Car.class));

        int count = context.getBeanDefinitionCount();
        System.out.println(count);


    }

}
